<?php

namespace plugin\colecron\app\admin\controller;

use app\common\controller\BaseAdminController;
use Carbon\Carbon;
use plugin\colecron\app\service\CronService;
use support\exception\BadException;

class CronLogController extends BaseAdminController
{

    public function list()
    {
        $crontab_id = input('crontab_id');
        if (!$crontab_id){
            throw new BadException("crontab_id参数错误");
        }
        $form = request()->getForm();
        $where = [];
        if ($form["start_time"] && $form["end_time"]){
            $where[] = ['create_time','between',[
                Carbon::parse($form["start_time"])->startOfDay()->getTimestamp(),
                Carbon::parse($form["end_time"])->endOfDay()->getTimestamp(),
            ]];
        }
        $result = CronService::crontabLog([
            'limit' => $form->getPageSize(),
            'page' => $form->getPage(),
            'where' => $where,
            'crontab_id' => $crontab_id,
        ]);
        return json($result);
    }


}
